package com.wyzz.hr.io.extend;

import com.wyzz.hr.pojo.Inmatch;
import com.wyzz.hr.pojo.InmatchModel;
import com.wyzz.hr.util.excel.ExcelFormat;
import com.wyzz.hr.util.excel.IExportToExcel;

import java.util.Iterator;
import java.util.List;
import jxl.format.Colour;
import jxl.write.*;

public class ExportInmatchModelToExcel extends IExportToExcel {

	public ExportInmatchModelToExcel(String filePathName,
			InmatchModel inmatchModel) throws Exception {
		cf = ExcelFormat.createBodyCellFormat(Colour.YELLOW);
		super.setFilePathName(filePathName);
		setInmatchModel(inmatchModel);
	}

	public void buildContent() throws Exception {
		int needTitle = 1 - inmatchModel.getImmNoTitle().intValue();
		WritableSheet ws = createSheet(sheetDefaultName, 0, writableWorkbook);
		int colNum = 0;
		for (Iterator it = inmatchModel.getImList().iterator(); it.hasNext();) {
			Inmatch inmatch = (Inmatch) it.next();
			if (inmatch.getImSampleWidth() != null
					&& inmatch.getImSampleWidth().intValue() > 0)
				ws.setColumnView(colNum, inmatch.getImSampleWidth().intValue());
			if (needTitle == 1) {
				if (inmatch.getImRequired().intValue() == 1)
					ws.addCell(new Label(colNum, 0, inmatch.getImFieldDesc(),
							cf));
				else
					ws.addCell(new Label(colNum, 0, inmatch.getImFieldDesc(),
							format.getTitleCellFormat()));
				ws.addCell(new Label(colNum++, needTitle,
						inmatch.getImSample(), format.getBodyCellFormat()));
			} else if (inmatch.getImRequired().intValue() == 1)
				ws.addCell(new Label(colNum++, needTitle,
						inmatch.getImSample(), cf));
			else
				ws.addCell(new Label(colNum++, needTitle,
						inmatch.getImSample(), format.getBodyCellFormat()));
		}

		writableWorkbook.write();
	}

	public InmatchModel getInmatchModel() {
		return inmatchModel;
	}

	public void setInmatchModel(InmatchModel inmatchModel) {
		this.inmatchModel = inmatchModel;
	}

	private InmatchModel inmatchModel;
	private WritableCellFormat cf;
}
